﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Text;

namespace PengSW.HeartBeat
{
    public class HeartBeatServiceClient : ClientBase<IHeartBeatService>, IHeartBeatService
    {
        public HeartBeatServiceClient(string aHost, string aServiceName, int aPort = 808)
            :base(new NetTcpBinding(), new EndpointAddress(string.Format(@"net.tcp://{0}:{1}/{2}", aHost, aPort, aServiceName)))
        {
        }

        public DateTime GetHeartBeat()
        {
            return base.Channel.GetHeartBeat();
        }

        public static bool TestHeartBeat(string aHost, string aServiceName, int aPort = 808)
        {
            try
            {
                using (HeartBeatServiceClient aClient = new HeartBeatServiceClient(aHost, aServiceName, aPort))
                {
                    aClient.GetHeartBeat();
                }
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}
